package eerbaar.v2.wait.internal;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import eerbaar.v2.app.core.ISprite;
import eerbaar.v2.app.images.Images;
import eerbaar.v2.app.tasks.IGameTask;
import eerbaar.v2.app.view2.SlideImage;
import eerbaar.v2.wait.Wait;

public class DisplayWaitTask implements IGameTask {

    private SlideImage waitImage;

    @Override
    public void doTask(Graphics2D g) {

        // MainWindow window = App.instance().getMainWindow();
        //
        // Canvas canvas = window.getCanvas();
        // Graphics2D g = (Graphics2D) canvas.getBufferStrategy()
        // .getDrawGraphics();

        if (Wait.getInstance().getCount() > 0) {

            Composite save = g.getComposite();

            int type = AlphaComposite.SRC_OVER;
            AlphaComposite alpha = AlphaComposite.getInstance(type, 0.3f);
            g.setComposite(alpha);

            g.setColor(Color.BLACK);
            g.fillRect(0, 0, 500, 500);

            g.setComposite(save);

            if (this.waitImage == null) {
                ISprite sprite = Images.instance().waiting();
                this.waitImage = new SlideImage(sprite);
            }

            Rectangle r = new Rectangle(250 - 16, 250 - 16, 32, 32);
            this.waitImage.drawImage(r, g);

        }
    }

    @Override
    public Priority getPriority() {
        return Priority.AFTER_AFTER_LAST;
    }

    @Override
    public int getRate() {
        return 1;
    }

    @Override
    public boolean runWhenSuspended() {
        return true;
    }

}
